class VMGrenade extends NadeW;

var() class<Projectile> ProjectileClass;
var() int NumProjectiles;
var PanzerfaustTrail SmokeTrail;

simulated function PostBeginPlay()
{
    local rotator SmokeRotation;

    if ( Level.NetMode != NM_DedicatedServer)
    {       
        SmokeTrail.SetBase(self);
        SmokeRotation.Pitch = 32768;
        SmokeTrail.SetRelativeRotation(SmokeRotation);        
    }

	if ( Role == ROLE_Authority )
	{
		Velocity = Speed * Vector(Rotation);
		RandSpin(25000);
		bCanHitOwner = false;
		if (Instigator.HeadVolume.bWaterVolume)
		{
			bHitWater = true;
			Velocity = 0.6*Velocity;
		}
	}
}

simulated function Destroyed()
{

	if ( SmokeTrail != None )
	{
		SmokeTrail.HandleOwnerDestroyed();
	}


	if ( Trail != None )
		Trail.mRegen = false; // stop the emitter from regenerating
	if( !bHasExploded && !bHidden )
		Explode(Location,vect(0,0,1));

	if ( Fear != None )
		Fear.Destroy();

	Super.Destroyed();
}

simulated function Explode(vector HitLocation, vector HitNormal)
{
	local PlayerController  LocalPlayer;	

	bHasExploded = True;
	BlowUp(HitLocation);

	// Incendiary Effects..
	//PlaySound(sound'ewmutsound.explode_smoke',,100.5*TransientSoundVolume);

	Spawn(ProjectileClass,Instigator, '', HitLocation + HitNormal*20, Rotation);
	
	if ( EffectIsRelevant(Location,false) )
	{
		Spawn(class'expbulletM',self,,HitLocation, rotator(-HitNormal));
	}	

	// Shake nearby players screens
	LocalPlayer = Level.GetLocalPlayerController();
	if ( (LocalPlayer != None) && (VSize(Location - LocalPlayer.ViewTarget.Location) < (DamageRadius * 1.5)) )
		LocalPlayer.ShakeView(RotMag, RotRate, RotTime, OffsetMag, OffsetRate, OffsetTime);
	Destroy();
}

simulated function ProcessTouch( actor Other, vector HitLocation )
{
	if (Other.IsA('NetKActor'))
		KAddImpulse(Velocity,HitLocation,);

    if( ExtendedZCollision(Other) != none )
    {
        return;
    }

    super.ProcessTouch(Other, HitLocation);


}

defaultproperties
{
     ProjectileClass=Class'PerksSimHostOrg.VirusMistField'
     Speed=1250.000000
     MaxSpeed=1250.000000
     Damage=325.000000
     DamageRadius=200.000000
     MyDamageType=Class'PerksSimHostOrg.DamTypeAcid'
     StaticMesh=StaticMesh'SCStaticMeshes.HHGrenadeSM'
     DrawScale=0.300000
     Skins(0)=Texture'kf_fx_trip_t.siren.siren_scream_energy'
}
